package com.wkbb.basic.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wkbb.basic.feign.DoorFeignService;
import com.wkbb.basic.feign.TcCloudFeignService;
import com.wkbb.basic.mapper.FamilyMapper;
import com.wkbb.basic.mapper.UserInfoMapper;
import com.wkbb.basic.mapper.UserMapper;
import com.wkbb.basic.mapper.YoutuPersonMapper;
import com.wkbb.basic.model.*;
import com.wkbb.basic.service.*;
import com.wkbb.basic.thread.*;
import com.wkbb.basic.utils.FillEmptyHeadImgUtil;
import com.wkbb.basic.vo.FamilyManageEditVo;
import com.wkbb.basic.vo.FamilyManagePageListVo;
import com.wkbb.common.base.BaseServiceImpl;
import com.wkbb.common.config.ServiceConfig;
import com.wkbb.common.constants.ErrorCode;
import com.wkbb.common.constants.RedisKeyConstant;
import com.wkbb.common.dto.ResultDTO;
import com.wkbb.common.dto.basic.FamilyInfoDto;
import com.wkbb.common.dto.basic.OrganizationDto;
import com.wkbb.common.dto.basic.StudentInfoDto;
import com.wkbb.common.dto.im.GroupUserInfoDto;
import com.wkbb.common.dto.im.ImBulkRegisterImAccountDto;
import com.wkbb.common.dto.im.ImUserNum;
import com.wkbb.common.enums.*;
import com.wkbb.common.redis.RedisTemplateUtil;
import com.wkbb.common.utils.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * @author dengjingyuan
 * @date 2019-07-04 17:31
 */
@Service
@Slf4j
public class FamilyServiceImpl extends BaseServiceImpl<Family> implements FamilyService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Autowired
    private UserService userService;

    @Autowired
    private FamilyMapper familyMapper;

    @Autowired
    private UserOpenService userOpenService;

    @Autowired
    private UserInfoService userInfoService;

    @Autowired
    @Lazy
    private XmppService xmppService;

    @Autowired
    private ClassInfoService classInfoService;


    @Autowired
    private DoorFeignService doorFeignService;

    @Autowired
    private YouTuService youTuService;

    @Autowired
    private OrganizationService organizationService;

    @Autowired
    private WebankService webankService;

    @Autowired
    private YoutuPersonMapper youtuPersonMapper;

    @Autowired
    private RedisTemplateUtil redisTemplateUtil;

    @Autowired
    public void setMapper(FamilyMapper mapper) {
        super.setMapper(mapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public FamilyInfoDto insertWithFamily(FamilyInfoDto familyInfoDto, String createBy, Boolean flag) {
        Long userId = insert(familyInfoDto, createBy);
        return insertFamily(familyInfoDto, userId, createBy, flag);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long insert(FamilyInfoDto familyInfoDto, String createBy) {
        if (StringUtil.isNullOrBlank(familyInfoDto.getSex())) {
            String sex = FillEmptyHeadImgUtil.checkFamilySex(familyInfoDto.getRelationType());
            familyInfoDto.setSex(sex);
        }

        //因为学生处可以新增家长，所以判断头像在这里判断
        //检查头像
        String headImg = FillEmptyHeadImgUtil.checkHeadImg(familyInfoDto.getSex(), RoleTypeEnum.FAMILY.getValue(), familyInfoDto.getHeadImgUrl(), false);
        if (!StringUtil.isNullOrBlank(headImg)) {
            log.info("默认头像地址：" + headImg);
            familyInfoDto.setHeadImgUrl(headImg);
        }

        User newUser = new User();
        BeanUtils.copyProperties(familyInfoDto, newUser);
        newUser.setId(null);
        newUser.setRoleType(userService.updateRoleTypeJson(null, null, Short.parseShort("" + RoleTypeEnum.FAMILY.getValue()), null, familyInfoDto.getOrgId(), null));
        newUser.setStatus(true);
        newUser.setUserCode(UuIdUtil.getUserCodeByUUId());
        userService.insert(familyInfoDto.getOrgId(), newUser, RoleTypeEnum.FAMILY.getValue(), familyInfoDto.getSex(), UserTypeEnum.FAMILY.getValue().shortValue(), familyInfoDto.getSmartWxUserId(), familyInfoDto.getIsSmartSubscribe());

        UserInfo userInfo = new UserInfo();
        BeanUtils.copyProperties(familyInfoDto, userInfo);
        if (!StringUtils.isEmpty(familyInfoDto.getHeadImgUrl())) {
            userInfo.setHeadImgMd5(userService.getImageMD5(familyInfoDto.getHeadImgUrl()));
        }
        userInfo.setUserId(newUser.getId());
        userInfoMapper.insert(userInfo);

        return newUser.getId();
    }

    @Override
    public void insert(FamilyManageEditVo familyManageEditVo, String createBy, Boolean flag) throws Exception {
        FamilyInfoDto familyInfoDto = familyManageEditVo.getFamilyInfoDto();

        User user = userService.getByPrimaryKey(familyInfoDto.getUserId());
        Long userId;

        if (user != null) {
            userId = user.getId();
            //插入家长表
            insertManyFamily(familyManageEditVo, userId, createBy, flag);
            //有用户信息,修改roleType  JSON权限
            Object roleType = userService.updateRoleTypeJson(user.getRoleType(), null,
                    Short.parseShort("" + RoleTypeEnum.FAMILY.getValue()), null, familyInfoDto.getOrgId(), user.getId());
            user.setRoleType(roleType);
            userMapper.update(user);
            //更新redis
            userService.updateUserInfo(familyInfoDto.getOrgId(), userId);
        } else {
            userId = insert(familyInfoDto, createBy);
            //插入家长表
            insertManyFamily(familyManageEditVo, userId, createBy, flag);

        }

    }

    private void insertManyFamily(FamilyManageEditVo familyManageEditVo, Long userId, String createBy, Boolean flag) {
        FamilyInfoDto familyInfoDto = familyManageEditVo.getFamilyInfoDto();
        //插入用户信息
        familyInfoDto.setUserId(userId);

        List<StudentInfoDto> studentInfoDtoList = familyManageEditVo.getStudentInfoDtoList();
        if (studentInfoDtoList == null || studentInfoDtoList.isEmpty()) {
            return;
        }

        //循环绑定学生
        studentInfoDtoList.forEach(studentInfoDto -> {
            if (studentInfoDto == null || studentInfoDto.getUserId() == null || studentInfoDto.getUserId() == 0
                    || studentInfoDto.getClassId() == null || studentInfoDto.getClassId() == 0
                    || studentInfoDto.getOrgId() == null || studentInfoDto.getOrgId() == 0
                    || studentInfoDto.getGradeId() == null || studentInfoDto.getGradeId() == 0
                    || studentInfoDto.getRelationType() == null || RelationTypeEnum.getDesc(studentInfoDto.getRelationType()) == null) {
                return;
            }
            //继承学生信息
            familyInfoDto.setId(null);
            familyInfoDto.setStudentUserId(studentInfoDto.getUserId());
            familyInfoDto.setClassId(studentInfoDto.getClassId());
            familyInfoDto.setGradeId(studentInfoDto.getGradeId());
            familyInfoDto.setOrgId(studentInfoDto.getOrgId());
            familyInfoDto.setRelationType(studentInfoDto.getRelationType());

            insertFamily(familyInfoDto, familyInfoDto.getUserId(), createBy, flag);
        });
    }

    /**
     * 向家长表插入数据
     *
     * @param familyInfoDto 家长信息
     * @param userId        家长userId
     * @param createBy      操作人
     * @param flag          是否同步处理XMPP 1是0否
     */
    @Override
    public FamilyInfoDto insertFamily(FamilyInfoDto familyInfoDto, Long userId, String createBy, Boolean flag) {
        Family family = new Family();
        BeanUtils.copyProperties(familyInfoDto, family);

        family.setUserId(userId);
        family.setCreateBy(createBy);
        family.setUpdateBy(createBy);
        familyMapper.insert(family);

        //通过用户ID查询家长roleTye并更新
        User user = userMapper.getByPrimaryKey(userId);
        if (null != user) {
            user.setRoleType(userService.updateRoleTypeJson(user.getRoleType(), null, Short.parseShort("" + RoleTypeEnum.FAMILY.getValue()), null, familyInfoDto.getOrgId(), user.getId()));
            user.setMobile(familyInfoDto.getMobile());
            userMapper.update(user);
            //更新redis
            userService.updateUserInfo(familyInfoDto.getOrgId(), user.getId());

            //新增或者更新userSmart
            userService.repairUserSmart(family.getOrgId(), user.getId(), familyInfoDto.getSmartWxUserId(), familyInfoDto.getIsSmartSubscribe(),RoleTypeEnum.FAMILY.getValue());

            //保存unionid(企微)
            if(StringUtil.isNotEmpty(familyInfoDto.getUnionId())) {
                userOpenService.saveUserUnion(familyInfoDto.getOrgId(), user.getId(), familyInfoDto.getUnionId());
            }
        }

        if (flag) {
            //xmpp推送更新用户通行权限
            //BasicThreadPoolUtil.getExecutorService(new BasicThreadPoolUtil(serviceConfig)).execute(new SynUserAccessXmppTask(doorFeignService, family.getOrgId(), userId, RoleTypeEnum.FAMILY,xmppService,family.getId(),family.getStudentUserId(),family.getRelationType(),true,true,true,false,(short)RoleTypeEnum.FAMILY.getValue()));
           // ThreadPoolUtil.addPoolTask(new SynUserAccessXmppTask(doorFeignService, family.getOrgId(), userId, RoleTypeEnum.FAMILY, xmppService, family.getId(), family.getStudentUserId(), family.getRelationType(), true, true, true, false, (short) RoleTypeEnum.FAMILY.getValue(), null));
        }
        familyInfoDto.setUserId(userId);
        return familyInfoDto;
    }

    @Override
    public void update(FamilyInfoDto familyInfoDto, String updateBy) throws Exception {
        updateFamily(familyInfoDto, updateBy, false);
    }

    @Transactional(rollbackFor = Exception.class)
    public Map<String, Object> update(FamilyInfoDto familyInfoDto, String updateBy, boolean isBack) throws Exception {
        User user = userMapper.getByPrimaryKey(familyInfoDto.getUserId());

        if (StringUtil.isNullOrBlank(familyInfoDto.getSex())) {
            String sex = FillEmptyHeadImgUtil.checkFamilySex(familyInfoDto.getRelationType());
            familyInfoDto.setSex(sex);
        }

        //当头像为空,默认设置头像.否则走正常变更
        Boolean flag = false;
        if (!StringUtil.isEmptyIgnoreBlank(user.getHeadImgUrl())) {
            flag = true;
        }

        //检查默认头像
        String headImg = FillEmptyHeadImgUtil.checkHeadImg(familyInfoDto.getSex(), RoleTypeEnum.FAMILY.getValue(),
                StringUtil.isNullOrBlank(familyInfoDto.getHeadImgUrl()) ? user.getHeadImgUrl() : familyInfoDto.getHeadImgUrl(), flag);
        if (!StringUtil.isNullOrBlank(headImg)) {
            log.info("默认头像地址：" + headImg);
            familyInfoDto.setHeadImgUrl(headImg);
        }

        Object roleType = userService.updateRoleTypeJson(user.getRoleType(), null, Short.parseShort("" + RoleTypeEnum.FAMILY.getValue()), null, familyInfoDto.getOrgId(), user.getId());
        user.setRoleType(roleType);
        BeanUtils.copyProperties(familyInfoDto, user);
        user.setId(familyInfoDto.getUserId());
        user.setHeadImgUrl(familyInfoDto.getHeadImgUrl());
        if (null != familyInfoDto.getIsSmartSubscribe()) {
            user.setIsSmartSubscribe(familyInfoDto.getIsSmartSubscribe());
        }

        Map<String, Object> result = new HashMap<String, Object>();
        List<Family> familyListResult = new ArrayList<Family>();

        userService.update(familyInfoDto.getOrgId(), user, RoleTypeEnum.FAMILY.getValue(), isBack, familyInfoDto.getSmartWxUserId(), familyInfoDto.getIsSmartSubscribe());

        List<Family> familyList = familyMapper.getByUserId(familyInfoDto.getUserId());
        for (Family family : familyList) {
            //只有学生对的上的，才修改基础数据
            if (familyInfoDto.getStudentUserId() != null && family.getStudentUserId() != null
                    && family.getStudentUserId() == familyInfoDto.getStudentUserId().longValue()) {
                if (family.getRelationType().longValue() != familyInfoDto.getRelationType()) {
                    //若修改了学生家长关系

                    //修改IM群关系
                    log.info("修改IM群关系：family:{},student:{}", family.getUserId(), familyInfoDto.getStudentUserId());
                    User student = userMapper.getByPrimaryKey(familyInfoDto.getStudentUserId());
                    if (null != student) {
                        String relationTypeName = student.getName() + RelationTypeEnum.getDesc(familyInfoDto.getRelationType());
                       // tcCloudFeignService.updateAllGroupUserInfo(familyInfoDto.getUserId(), familyInfoDto.getOrgId(), RoleTypeEnum.FAMILY.getValue(), UserTypeEnum.FAMILY.getValue().shortValue(), UserTypeEnum.FAMILY.getValue().shortValue(), relationTypeName);
                    }

                }

                BeanUtils.copyProperties(familyInfoDto, family);
            } else {
                //学生对不上的，只修改手机号和卡号
                family.setMobile(familyInfoDto.getMobile());
                family.setCardNo(familyInfoDto.getCardNo());
                family.setRemark(familyInfoDto.getRemark());
            }
            family.setUpdateBy(updateBy);
            if (isBack) {
                familyMapper.updateBack(family);
            } else {
                update(family);
            }

            familyListResult.add(family);

        }

        Map<String, Object> params = new HashMap<>(1);
        params.put("userId", familyInfoDto.getUserId());
        UserInfo userInfo = userInfoMapper.getByMapParams(params);
        BeanUtils.copyProperties(familyInfoDto, userInfo);
        if (!StringUtils.isEmpty(familyInfoDto.getHeadImgUrl())) {
            userInfo.setHeadImgMd5(userService.getImageMD5(familyInfoDto.getHeadImgUrl()));
        }
        userInfoService.update(userInfo, isBack);

        //修改家长IM用户头像
        log.info("**********修改家长IM用户头像**********");
        //tcCloudFeignService.updateImUserInfo(familyInfoDto.getOrgId(), familyInfoDto.getUserId(), (short) RoleTypeEnum.FAMILY.getValue(), UserTypeEnum.FAMILY.getValue().shortValue(), user.getHeadImgUrl());

        //保存unionid(企微)
        if(StringUtil.isNotEmpty(familyInfoDto.getUnionId())) {
            userOpenService.saveUserUnion(familyInfoDto.getOrgId(), user.getId(), familyInfoDto.getUnionId());
        }

        result.put("familyListResult", familyListResult);
        return result;
    }

    @Override
    public void updateFamily(FamilyInfoDto familyInfoDto, String updateBy, boolean isBack) throws Exception {
        Map<String, Object> map = update(familyInfoDto, updateBy, isBack);
        List<Family> familyListResult = map.get("familyListResult") == null ? null : (List<Family>) map.get("familyListResult");
        if (familyListResult == null || familyListResult.isEmpty()) {
            return;
        }

        for (Family family : familyListResult) {

            if (familyInfoDto.getStudentUserId() != null && family.getStudentUserId() != null
                    && family.getStudentUserId() == familyInfoDto.getStudentUserId().longValue()) {
                if (family.getRelationType().longValue() != familyInfoDto.getRelationType()) {
                    //xmpp推送更新用户通行权限
                    ThreadPoolUtil.addPoolTask(new SynUserAccessXmppTask(doorFeignService, familyInfoDto.getOrgId(), familyInfoDto.getUserId(), RoleTypeEnum.FAMILY, xmppService, family.getId(), family.getStudentUserId(), family.getRelationType(), false, true, true, false, (short) RoleTypeEnum.FAMILY.getValue(), null));
                }
            }

            try {
                log.info("**********家长修改,删除宝宝所在班级的所有老师通讯录**********");
                ThreadPoolUtil.addPoolTask(new BacisDeleteAddressBookKeyTask(family.getUserId(), AddressListEnum.FAMILY.getValue(), family.getOrgId(), userOpenService));
                log.info("**********家长修改,删除宝宝所在班级的所有老师通讯录**********");
            } catch (Exception e) {
                log.error("**********家长修改,删除宝宝所在班级的所有老师通讯录异常**********");
            }
        }

        //xmpp推送更新用户通行权限
//        ThreadPoolUtil.addPoolTask(new SynUserAccessXmppTask(doorFeignService, familyInfoDto.getOrgId(), familyInfoDto.getUserId(), RoleTypeEnum.FAMILY, xmppService, familyInfoDto.getId(), familyInfoDto.getStudentUserId(), familyInfoDto.getRelationType(), true, false, true, false, (short) RoleTypeEnum.FAMILY.getValue(), null));
    }

    /**
     * 修改家长历史卡号手机号
     *
     * @param familyInfoDto 需要修改的家长
     * @throws Exception 异常
     */
    @Override
    public void updateFamilyHistory(FamilyInfoDto familyInfoDto) throws Exception {
        if (familyInfoDto.getUserId() == null) {
            return;
        }

        List<Family> familyList = familyMapper.getByUserId(familyInfoDto.getUserId());
        for (Family family : familyList) {
            family.setMobile(familyInfoDto.getMobile());
            family.setCardNo(familyInfoDto.getCardNo());
            update(family);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateMobile(FamilyInfoDto familyInfoDto) throws Exception {

        User user = userMapper.getByPrimaryKey(familyInfoDto.getUserId());

        user.setId(familyInfoDto.getUserId());
        user.setMobile(familyInfoDto.getMobile());//修改手机号
        Object roleType = userService.updateRoleTypeJson(user.getRoleType(), null, Short.parseShort("" + RoleTypeEnum.FAMILY.getValue()), null, familyInfoDto.getOrgId(), user.getId());
        user.setRoleType(roleType);
        userService.update(familyInfoDto.getOrgId(), user, RoleTypeEnum.FAMILY.getValue(), false, familyInfoDto.getSmartWxUserId(), familyInfoDto.getIsSmartSubscribe());

        List<Family> familyList = familyMapper.getByUserId(familyInfoDto.getUserId());
        for (Family family : familyList) {

            //学生对不上的，只修改手机号
            Family familyInfo = new Family();
            familyInfo.setUserId(family.getUserId());
            familyInfo.setMobile(familyInfoDto.getMobile());

            super.update(familyInfo);

            try {
                log.info("**********家长修改,删除宝宝所在班级的所有老师通讯录**********");
                ThreadPoolUtil.addPoolTask(new BacisDeleteAddressBookKeyTask(family.getUserId(), AddressListEnum.FAMILY.getValue(), family.getOrgId(), userOpenService));
                log.info("**********家长修改,删除宝宝所在班级的所有老师通讯录**********");
            } catch (Exception e) {
                log.error("**********家长修改,删除宝宝所在班级的所有老师通讯录异常**********");
            }
        }
    }

    @Transactional(rollbackFor = Exception.class)
    public Map<String, Object> delete(List<Long> ids, String deleteBy) throws Exception {
        Map<String, Object> result = new HashMap<>(2);
        if (ids.isEmpty()) {
            result.put("resultDTO", new ResultDTO(ErrorCode.PARAM_MISSING));
            return result;
        }


        List<Family> familyList = new ArrayList<>();
        for (Long id : ids) {
            if (id == null || id == 0) {
                result.put("resultDTO", new ResultDTO(ErrorCode.PARAM_MISSING));
                return result;
            }

            Family family = familyMapper.getByPrimaryKey(id);

            if (null != family) {
                //IM相关结束---------------------------批量删除家长---------------------------
                ResultDTO resultDto = userOpenService.operateGroupUser(ImOperGroupTypeEnum.OUT_GROUP.getValue(), family.getOrgId(), family.getClassId(), family.getUserId(), family.getStudentUserId(), RoleTypeEnum.FAMILY.getValue(), UserTypeEnum.FAMILY.getValue(), true);
                if (!resultDto.isSuccess()) {
                    result.put("resultDTO", resultDto);
                    return result;
                }

                //删除家长对应删除IM账号缓存
                /*ResultDTO<Object> imUserRedis = tcCloudFeignService.getImUserRedis(family.getUserId(), family.getOrgId(), (short) RoleTypeEnum.FAMILY.getValue(), UserTypeEnum.FAMILY.getValue().shortValue());
                if (ResultDTO.checkSuccess(imUserRedis) && null != imUserRedis.getData()) {
                    log.info("----------清除该用户IM缓存----------userId:{}", family.getUserId());
                    redisTemplateUtil.delete(imUserRedis.getData().toString());
                }*/

                //IM相关结束---------------------------批量删除家长---------------------------

                //处理通讯录开始----------------------开始处理通讯录---------------------------
                try {
                    log.info("**********家长修改,删除宝宝所在班级的所有老师通讯录**********");
                    ThreadPoolUtil.addPoolTask(new BacisDeleteAddressBookKeyTask(family.getUserId(), AddressListEnum.FAMILY.getValue(), family.getOrgId(), userOpenService));
                    log.info("**********家长修改,删除宝宝所在班级的所有老师通讯录**********");
                } catch (Exception e) {
                    log.error("**********家长修改,删除宝宝所在班级的所有老师通讯录异常**********");
                }
                //处理通讯录结束----------------------处理通讯录结束---------------------------

                //删除user表中角色信息
                Family deleteFamily = new Family();
                deleteFamily.setId(id);
                deleteFamily.setStatus(false);
                deleteFamily.setUpdateBy(deleteBy);
                familyMapper.update(deleteFamily);

                familyList.add(family);

                checkChildrenExist(family.getOrgId(), family.getUserId());

               // userService.deleteRedisWkbbBasicUserBack(family.getUserId(), family.getOrgId());
            }
        }

        result.put("familyList", familyList);
        return result;
    }

    @Override
    public ResultDTO deleteFamily(List<Long> ids, String deleteBy) throws Exception {
        Map<String, Object> result = delete(ids, deleteBy);

        ResultDTO resultDTO = result.get("resultDTO") == null ? null : (ResultDTO) result.get("resultDTO");
        List<Family> familyList = result.get("familyList") == null ? null : (List<Family>) result.get("familyList");

        if (resultDTO != null) {
            return resultDTO;
        }

        familyList.forEach(
                family -> {
                    //xmpp推送更新用户通行权限
                    ThreadPoolUtil.addPoolTask(new SynUserAccessXmppTask(doorFeignService, family.getOrgId(), family.getStudentUserId(), RoleTypeEnum.FAMILY, 1, xmppService, family.getId(), family.getStudentUserId(), family.getRelationType(), false, true, true, true, (short) RoleTypeEnum.FAMILY.getValue(), null));
                }
        );
        return new ResultDTO(true);
    }

    /**
     * 检查这个用户在这个学校还有没有孩子
     *
     * @param orgId  学校ID
     * @param userId 用户ID
     */
    private void checkChildrenExist(Long orgId, Long userId) throws Exception {
        Map<String, Object> params = new HashMap<>(2);
        params.put("orgId", orgId);
        params.put("userId", userId);
        List<Family> familyList = familyMapper.getListByMapParams(params);
        //如果该家长在这个学校没有孩子了，就在这个学校删掉他的家长身份
        if (familyList == null || familyList.isEmpty()) {
            userService.deleteUserInfo(orgId, userId, RoleTypeEnum.FAMILY.getValue());
            //xmpp推送更新用户通行权限
            ThreadPoolUtil.addPoolTask(new SynUserAccessXmppTask(doorFeignService, orgId, userId, RoleTypeEnum.FAMILY, xmppService, null, null, null, true, false, true, false, (short) RoleTypeEnum.FAMILY.getValue(), null));
        }
    }

    @Override
    public FamilyInfoDto getFamilyInfoById(Long id) {
        return familyMapper.getFamilyInfoById(id);
    }

    @Override
    public PageInfo<FamilyInfoDto> getFamilyInfoList(Map<String, Object> params, Integer pageNo, Integer pageSize) {
        if (pageNo == null || pageSize == null) {
            return null;
        }
        Page<FamilyInfoDto> page = PageHelper.startPage(pageNo, pageSize, true);
        PageInfo<FamilyInfoDto> pageInfo = new PageInfo<>(
                familyMapper.getFamilyInfoPageList(params));
        pageInfo.setTotal(page.getTotal());
        return pageInfo;
    }

    @Override
    public PageInfo<Family> getFamilyListByPage(HashMap<String, Object> params, Integer pageNo, Integer pageSize) {
        if (pageNo == null || pageSize == null) {
            return null;
        }
        Page<Family> page = PageHelper.startPage(pageNo, pageSize, true);
        PageInfo<Family> pageInfo = new PageInfo<Family>(familyMapper.getFamilyListByPage(params));
        pageInfo.setTotal(page.getTotal());
        return pageInfo;
    }

    @Override
    public PageInfo<FamilyManagePageListVo> getFamilyManageList(Map<String, Object> params, Integer pageNo, Integer pageSize) {
        if (pageNo == null || pageSize == null) {
            return null;
        }
        Page<FamilyManagePageListVo> page = PageHelper.startPage(pageNo, pageSize, true);
        PageInfo<FamilyManagePageListVo> pageInfo = new PageInfo<>(familyMapper.getFamilyManagePageList(params));

        //加上是否已经上传人脸判断
//        List<FamilyManagePageListVo> list = pageInfo.getList();
       /* if (CollectionUtils.isNotEmpty(list)) {
            for (FamilyManagePageListVo familyManagePageListVo : list) {
                List<FamilyInfoDto> familyInfoDtoList = familyManagePageListVo.getFamilyList();
                if (CollectionUtils.isNotEmpty(familyInfoDtoList)) {
                    Long accountId = userOpenService.getAccountIdByOrgId(familyInfoDtoList.get(0).getOrgId());
                    for (FamilyInfoDto familyInfoDto : familyInfoDtoList) {
                        //加上accountId
                        familyInfoDto.setAccountId(accountId);
                        Boolean hasUploadFace = youTuService.checkHasUploadFace(familyInfoDto.getOrgId(), familyInfoDto.getUserId());
                        familyInfoDto.setHasUploadFace(hasUploadFace);
                    }
                }
            }
        }*/

        pageInfo.setTotal(page.getTotal());
        return pageInfo;
    }

    @Override
    public PageInfo<FamilyInfoDto> getFamilyInfoPageByClassId(Map<String, Object> params, Integer pageNo, Integer pageSize) {
        if (pageNo == null || pageSize == null) {
            return null;
        }

        Page<FamilyInfoDto> page = PageHelper.startPage(pageNo, pageSize, true);
        PageInfo<FamilyInfoDto> pageInfo = new PageInfo<>(getFamilyInfoListByClassId(params));
        pageInfo.setTotal(page.getTotal());
        return pageInfo;
    }

    @Override
    public List<FamilyInfoDto> getFamilyInfoListByClassId(Map<String, Object> params) {
        return familyMapper.getFamilyInfoListByClassId(params);
    }

    @Override
    public List<Family> getFamilyListUniqueByOrgId(Long orgId) {
        return familyMapper.getFamilyListUniqueByOrgId(orgId);
    }

    @Override
    public List<Family> getFamilyListByStudentId(Long id) {
        Map<String, Object> params = new HashMap<>(1);
        params.put("studentId", id);
        return familyMapper.getListByMapParams(params);
    }

    @Override
    public void deleteByStudentId(Long orgId, Long studentId, String deleteBy) throws Exception {
        Map<String, Object> params = new HashMap<>(2);
        params.put("orgId", orgId);
        params.put("studentId", studentId);

        List<Family> familyList = familyMapper.getListByMapParams(params);
        List<Long> familyIdList = new ArrayList<>();
        for (Family family : familyList) {
            familyIdList.add(family.getId());
        }

        delete(familyIdList, deleteBy);
    }

    @Override
    public FamilyInfoDto getFamilyInfoByMobile(String mobile) {
        Map<String, Object> params = new HashMap<>(1);
        params.put("mobile", mobile);
        return familyMapper.getFamilyInfoByMobile(params);
    }

    /**
     * 根据家长userId查询家长列表
     *
     * @param params
     * @return
     */
    @Override
    public List<FamilyInfoDto> getFamilyListByFamily(Map<String, Object> params) {
        return familyMapper.getFamilyListByFamily(params);
    }

    @Override
    public List<Map<String, Object>> getFamilyCountStatByOrgId(Long orgId) {
        return familyMapper.getFamilyCountStatByOrgId(orgId);
    }

    @Override
    public List<ImUserNum> getFamilyList(Map<String, Object> params) {
        return familyMapper.getFamilyList(params);
    }

    @Override
    public List<Family> getFamilyListByUserIds(List<Long> userIds,Long orgId) {
        HashMap<String, Object> param = new HashMap<>();
        param.put("userIds", userIds);
        param.put("orgId", orgId);
        return familyMapper.getFamilyListByUserIds(param);
    }

    public List<Family> getErrorFamilyList(List<Long> userIds,Long orgId) {
        HashMap<String, Object> param = new HashMap<>();
        param.put("userIds", userIds);
        param.put("orgId", orgId);
        return familyMapper.getErrorFamilyList(param);
    }

    @Override
    public List<Family> getFamilyListByUpdateTime(Long orgId, Date date) {
        HashMap<String, Object> param = new HashMap<>();
        param.put("orgId", orgId);
        param.put("updateTime", date);
        return familyMapper.getFamilyListByUpdateTime(param);
    }

    /**
     * 导出家长列表
     *
     * @param params 参数
     * @return 家长分页列表
     */
    @Override
    public List<Object[]> exportFamilyExcel(Map<String, Object> params) throws Exception {
        Long orgId = (Long) params.get("orgId");
        OrganizationDto organizationDto = organizationService.getInfo(orgId);

        List<FamilyInfoDto> familyList = familyMapper.getFamilyStudentList(params);
        log.info("********exportFamilyExcel orgId:{} size:{}", orgId, familyList.size());
        if (CollectionUtils.isNotEmpty(familyList)) {

            List<Object[]> data = new ArrayList<>(familyList.size());

            //返回教职工数据
            familyList.forEach(e -> {

                Object[] d = new Object[9];
                int i = 0;
                d[i++] = organizationDto.getName() == null ? "-" : organizationDto.getName();
                d[i++] = e.getName() == null ? "-" : e.getName();
                d[i++] = e.getMobile() == null ? "-" : e.getMobile();
                d[i++] = e.getCardNo() == null ? "-" : e.getCardNo();
                d[i++] = e.getHasUploadFace() == null ? "-" : e.getHasUploadFace() == true ? "已上传" : "未上传";
                d[i++] = e.getCreateTime() == null ? "-" : e.getCreateTime();
                d[i++] = e.getRelationTypeName() == null ? "-" : e.getRelationTypeName();
                d[i++] = e.getStudentName() == null ? "-" : e.getStudentName();
                d[i++] = StringUtil.isEmptyIgnoreBlank(e.getClassName()) ? "-" : e.getClassName();
                data.add(d);
            });
            return data;
        }

        return null;
    }

    /**
     * 根据学生userId查询家长列表
     *
     * @param params
     * @return
     */
    @Override
    public List<FamilyInfoDto> getFamilyListByStudent(Map<String, Object> params) {
        return familyMapper.getFamilyListByStudent(params);
    }



    public void repairFamilyIm(List<Long> familyListAll,Long orgId) throws IllegalAccessException, InstantiationException {
        List<Family> familyListByUserIds = getFamilyListByUserIds(familyListAll,orgId);

        //IM每个班级进行分组
        if (CollectionUtils.isNotEmpty(familyListByUserIds)) {
            Map<Long, List<Family>> collect = familyListByUserIds.stream().collect(Collectors.groupingBy(family -> family.getClassId()));
            for (Map.Entry<Long, List<Family>> groupFamilyList : collect.entrySet()) {
                List<FamilyInfoDto> familyInfoDtoList = BeanUtil.copyPropertiesList(groupFamilyList.getValue(), FamilyInfoDto.class);
                ThreadPoolUtil.addTask(new ImSaveFamilyTask(classInfoService, familyInfoDtoList));
            }
        }
    }

    @Override
    public void getRepairFamilyList(Long orgId) {
        String redisKey = getRepairFamilyListRedis( orgId);

        log.info("\n修复家长IM账号控制............ 开始..准备开始获取分布式锁......orgId:{}" ,orgId);
        boolean lock = false;
        int retryCount = 0;
        while (!lock) {
            try {
                lock = redisTemplateUtil.tryLock(redisKey, orgId.toString(), 200, TimeUnit.SECONDS);
                log.info("#################" + redisKey, "加锁 ", orgId);

            } catch (Exception e) {
                log.info("#################加锁失败..等待锁过期 ：" + redisKey, orgId);
                e.printStackTrace();

            }

            if (lock) {//加锁成功
                try {
                    List<List<GroupUserInfoDto>> groupUserInfoDtoArrayList = new ArrayList<>();
                    //查询所有有效家长
                    HashMap<String, Object> param = new HashMap<>();
                    param.put("orgId", orgId);
                    log.info("----------准备开始处理所有家长----------orgId:{}", orgId);
                    List<ImUserNum> familyList = getFamilyList(param);

                    List<Long> familyListAll = familyMapper.getFamilyAll(param);
                    //创建需要移除的集合
                    List<Long> removeFamilyList = new ArrayList<>();

                    //创建一个家长多个小孩的集合
                    List<Long> muchFamilyList = new ArrayList<>();
                    try {

                        //查询IM所有已入群的家長
                        /*ResultDTO<List<ImUserNum>> imFamilyDto = tcCloudFeignService.getImFamily(orgId);
                        if (ResultDTO.checkSuccess(imFamilyDto)) {
                            if (CollectionUtils.isNotEmpty(familyList)) {
                                if (CollectionUtils.isNotEmpty(imFamilyDto.getData())) {
                                    familyList.forEach((e) -> {
                                        imFamilyDto.getData().forEach((im) -> {
                                            //如果用户ID一样并且数量一样
                                            if (im.getUserId().intValue() == e.getUserId().intValue() && e.getNum() == im.getNum()) {
                                                removeFamilyList.add(e.getUserId());
                                                //如果用户ID一样但是数量不一样
                                            } else if (im.getUserId().intValue() == e.getUserId().intValue() && e.getNum() != im.getNum()) {
                                                muchFamilyList.add(e.getUserId());
                                            }
                                        });
                                    });

                                    log.info("----------家长已入群用户ID一样并且数量一样----------orgId:{},removeFamilyList:{}", orgId, removeFamilyList.size());

                                    //查詢所有未入群的家長并且没有IM账号
                                    familyListAll.removeAll(removeFamilyList);
                                    familyListAll.removeAll(muchFamilyList);

                                    log.info("----------已区分未入群并且没IM账号和已入群,入群数量和小孩数量不一致情况----------orgId:{}", orgId);
                                    if (CollectionUtils.isNotEmpty(familyListAll)) {
                                        log.info("----------开始处理未入群并且没IM账号家长----------orgId:{},familyListAll:{}", orgId, familyListAll.size());
                                        //处理所有未入群的家長并且没有IM账号的家长
                                        groupUserInfoDtoArrayList=getRepairFamilyList(familyListAll,orgId,groupUserInfoDtoArrayList);
                                        log.info("----------处理未入群并且没IM账号家长异步结束----------orgId:{}", orgId);
                                    }

                                    if (CollectionUtils.isNotEmpty(muchFamilyList)) {
                                        log.info("----------开始处理家长入群数量和小孩数量不一致情况----------orgId:{},muchFamilyList:{}", orgId, muchFamilyList.size());
                                        //处理家长入群数量和小孩数量不一致情况
                                        groupUserInfoDtoArrayList=getRepairFamilyList(muchFamilyList,orgId,groupUserInfoDtoArrayList);
                                        log.info("----------处理家长入群数量和小孩数量不一致情况结束----------orgId:{}", orgId);
                                    }
                                } else {
                                    log.info("----------所有家长都未入群----------orgId:{},familyListAll:{}", orgId, familyListAll.size());
                                    groupUserInfoDtoArrayList=getRepairFamilyList(familyListAll,orgId,groupUserInfoDtoArrayList);
                                }
                            }
                        }*/
                    } catch (Exception e) {
                        log.error("----------查询当前学校需要修复的IM家长用户异常----------{}", e.getMessage());
                    }

                    log.info("需要修复的IM家长数量:{}", groupUserInfoDtoArrayList.size());

                    if(CollectionUtils.isNotEmpty(groupUserInfoDtoArrayList)){
                        log.info("----------准备批量处理IM用户入群----------");
                        ImBulkRegisterImAccountDto imBulkRegisterImAccountDto = new ImBulkRegisterImAccountDto();
                        imBulkRegisterImAccountDto.setOrgId(orgId);
                        imBulkRegisterImAccountDto.setRoleType((short)RoleTypeEnum.FAMILY.getValue());
                        imBulkRegisterImAccountDto.setUserType(UserTypeEnum.FAMILY.getValue().shortValue());

                        familyListAll.addAll(muchFamilyList);
                        log.info("----------打印需要修复IM帐号----------familyListAll:{}",familyListAll.size());
                        imBulkRegisterImAccountDto.setUserIdList(familyListAll);

                        //ThreadPoolUtil.addPoolTask(new ImBulkRegisterImAccountTask(tcCloudFeignService, imBulkRegisterImAccountDto));
                        log.info("----------批量修复IM帐号结束----------familyListAll:{}", familyListAll.size());
                        //ThreadPoolUtil.addPoolTask(new ImRepairFamilyExcleTask(tcCloudFeignService, groupUserInfoDtoArrayList, orgId,redisTemplateUtil));
                    }
                } catch (Exception e) {
                    log.error("---------新增用户入群失败----------e:{}", e.getMessage());
                } finally {
                    log.info("#################" + redisKey, "开始释放锁 ", orgId);
                    redisTemplateUtil.releaseLock(redisKey, orgId.toString());
                    log.info("#################" + redisKey, "释放锁成功 ", orgId);
                }

                try {
                    redisTemplateUtil.releaseLock(redisKey, orgId.toString());
                } catch (Exception e) {
                    log.info("#################释放锁失败..等待锁过期 ," + redisKey, "释放锁成功 ", orgId.toString());
                }
            } else {
                try {
                    retryCount++;
                    if(retryCount>20){
                        log.info("加锁失败，重试超过20次，修复家长IM账号失败...orgId:{}" ,  orgId);
                        break;
                    }
                    log.info("等待500ms重试..." + redisKey, "释放锁成功 ", orgId.toString());
                    Thread.sleep(500L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public String getRepairFamilyImRedis(Long orgId) {
        return RedisKeyConstant.WKBB_EDUCATION_COMMUNITY_IM + "Family:" + "orgId:" + orgId;
    }

    @Override
    public List<Long> getFamilyListAll(Long orgId) {
        HashMap<String, Object> param = new HashMap<>();
        param.put("orgId", orgId);
        //如果学校ID为NUll,自动获取当前创建家长
        if(null==orgId){
            param.put("createTime",TimeUtil.getCurrentBeginDate());
        }
        return familyMapper.getFamilyAll(param);
    }

    public List<List<GroupUserInfoDto>> getRepairFamilyList(List<Long> familyListAll,Long orgId,List<List<GroupUserInfoDto>> repairFamilyList){
        try{
            List<Family> familyListByUserIds = getFamilyListByUserIds(familyListAll,orgId);

            //IM每个班级进行分组
            if (CollectionUtils.isNotEmpty(familyListByUserIds)) {
                Map<Long, List<Family>> collect = familyListByUserIds.stream().collect(Collectors.groupingBy(Family::getClassId));
                for (Map.Entry<Long, List<Family>> groupFamilyList : collect.entrySet()) {
                    List<FamilyInfoDto> familyInfoDtoList = BeanUtil.copyPropertiesList(groupFamilyList.getValue(), FamilyInfoDto.class);
                    repairFamilyList.add(classInfoService.getRepairFamilyList(familyInfoDtoList));
                }
            }
        }catch (Exception e){
            log.error("----------获取需要入群的家长集合失败----------",e);
        }
        return repairFamilyList;
    }


    public String getRepairFamilyListRedis(Long orgId) {
        return RedisKeyConstant.WKBB_EDUCATION_COMMUNITY_IM + "RepairFamilyListRedis:" + "orgId:" + orgId;
    }

	@Override
    public List<FamilyInfoDto> getFamilyListByFamilySmartUserId(Map<String, Object> params)
    {
        return familyMapper.getFamilyListByFamilySmartUserId(params);
    }

    @Override
    public Map<String,Integer> statFamilyInfo(Long orgId,Long gradeId,Long classId)
    {
        HashMap<String, Object> params = new HashMap<>();
        params.put("orgId", orgId);
        params.put("gradeId", gradeId);
        params.put("classId", classId);
        Map<String,Object> familyStatMap = familyMapper.statFamilyInfo(params);

        Map<String,Integer> map = new HashMap<String,Integer>();
        if(!familyStatMap.isEmpty()) {
            int familyCount = null==familyStatMap.get("familyCount")?0:Integer.parseInt((String)familyStatMap.get("familyCount"));
            int faceCount = null==familyStatMap.get("faceCount")?0:Integer.parseInt((String)familyStatMap.get("faceCount"));
            int openFlagCount = null==familyStatMap.get("openFlagCount")?0:Integer.parseInt((String)familyStatMap.get("openFlagCount"));
            map.put("familyCount", familyCount);
            map.put("faceCount", faceCount);
            map.put("faceNoCount", familyCount - faceCount);
            map.put("openFlagCount", openFlagCount);
            map.put("openFlagNoCount", familyCount - openFlagCount);
        }

        return map;
    }

    @Override
    public void operateFaceFlag(Long orgId,Long familyUserId,Boolean faceFlag) throws Exception
    {
        HashMap<String, Object> params = new HashMap<>();
        params.put("orgId", orgId);
        params.put("userId", familyUserId);

        List<Family> familyList = familyMapper.getListByMapParams(params);
        if(!familyList.isEmpty())
        {
            for(Family family : familyList) {
                Family familyInfo = new Family();
                familyInfo.setId(family.getId());
                familyInfo.setFaceFlag(faceFlag);
                familyMapper.update(familyInfo);
            }

            //如果是关闭，则删除对应家长人脸
            if(!faceFlag) {
                YoutuPerson youtuPerson = youtuPersonMapper.getByMapParams(params);
                if (null != youtuPerson) {
                    String result = webankService.modifyFace(youtuPerson.getPersonId(), orgId, true, null, null, null);
                }
            }
        }
    }

    /**
     * 打开学校人脸配置同步家长人脸开关
     * */
    @Override
    public void syncFaceFlag(Long orgId) throws Exception
    {

        List<Family> updateList = new ArrayList<>();

        HashMap<String, Object> params = new HashMap<>();
        params.put("orgId", orgId);
        List familyList = familyMapper.getListByMapParams(params);

        //分页处理
        Integer total = familyList.size();
        Integer pageSize = 100;
        Integer pages = (total + pageSize - 1) / pageSize;
        for (int currentPage = 1; currentPage <= pages; currentPage++) {
            List<Family> dataList = ListUtil.page(currentPage, pageSize, familyList);
            if (!dataList.isEmpty()) {
                for (Family family : dataList) {
                    if(null==family.getFaceFlag()) {
                        HashMap<String, Object> personParams = new HashMap<>();
                        personParams.put("orgId", orgId);
                        personParams.put("userId", family.getUserId());
                        YoutuPerson youtuPerson = youtuPersonMapper.getByMapParams(personParams);
                        if (null != youtuPerson) {
                            family.setFaceFlag(true);
                        } else {
                            family.setFaceFlag(false);
                        }
                        updateList.add(family);
                    }
                }

                //批量修改
                if(!updateList.isEmpty()) {
                    familyMapper.updateFaceFlagBatch(updateList);
                }
            }
        }
    }

    @Override
    public void repairFamilyImTask(){
        HashMap<String, Object> params = new HashMap<>();
        log.info("----------准备获取当天系统所有正常家长----------");

        params.put("createTime",TimeUtil.getCurrentBeginDate());
        //查询所有有效家长
        log.info("----------准备开始处理所有家长----------", params);
        List<ImUserNum> familyList = getFamilyList(params);

        if(CollectionUtils.isNotEmpty(familyList)){
            HashMap<String, Object> userIdParam = new HashMap<>();
            List<Long> userIds = familyList.stream().map(ImUserNum::getUserId).collect(Collectors.toList());
            userIdParam.put("userIds", userIds);
            familyList =getFamilyList(userIdParam);
        }
        //再次获取
        List<Long> familyListAll = familyMapper.getFamilyAll(params);
        //创建需要移除的集合
        List<Long> removeFamilyList = new ArrayList<>();

        //创建一个家长多个小孩的集合
        List<Long> muchFamilyList = new ArrayList<>();

        List<Family> familyErrorList=new ArrayList<>();
        try {

            //查询IM所有已入群的家長
           /* ResultDTO<List<ImUserNum>> imFamilyDto = tcCloudFeignService.getImFamily(null);
            if (ResultDTO.checkSuccess(imFamilyDto)) {
                if (CollectionUtils.isNotEmpty(familyList)) {
                    if (CollectionUtils.isNotEmpty(imFamilyDto.getData())) {
                        familyList.forEach((e) -> {
                            imFamilyDto.getData().forEach((im) -> {
                                //如果用户ID一样并且数量一样
                                if (im.getUserId().intValue() == e.getUserId().intValue() && e.getNum() == im.getNum()) {
                                    removeFamilyList.add(e.getUserId());
                                    //如果用户ID一样但是数量不一样
                                } else if (im.getUserId().intValue() == e.getUserId().intValue() && e.getNum() != im.getNum()) {
                                    muchFamilyList.add(e.getUserId());
                                }
                            });
                        });
                        log.info("----------家长已入群用户ID一样并且数量一样----------removeFamilyList",  removeFamilyList.size());

                        //查詢所有未入群的家長并且没有IM账号
                        familyListAll.removeAll(removeFamilyList);
                        familyListAll.removeAll(muchFamilyList);

                        log.info("----------已区分未入群并且没IM账号和已入群,入群数量和小孩数量不一致情况----------");
                        if (CollectionUtils.isNotEmpty(familyListAll)) {
                            log.info("----------开始处理未入群并且没IM账号家长----------orgId:{},familyListAll", familyListAll.size());
                            //处理所有未入群的家長并且没有IM账号的家长
                            List<Family> familyListByUserIds = getErrorFamilyList(familyListAll,null);
                            log.info("----------处理未入群并且没IM账号家长异步结束----------familyListByUserIds:{}", familyListByUserIds.size());
                            familyErrorList.addAll(familyListByUserIds);
                        }

                        if (CollectionUtils.isNotEmpty(muchFamilyList)) {
                            log.info("----------开始处理家长入群数量和小孩数量不一致情况----------muchFamilyList", muchFamilyList.size());
                            //处理家长入群数量和小孩数量不一致情况
                            List<Family> familyListByUserIds = getErrorFamilyList(muchFamilyList,null);
                            familyErrorList.addAll(familyListByUserIds);
                            log.info("----------处理家长入群数量和小孩数量不一致情况结束----------familyListByUserIds:{}", familyListByUserIds.size());
                        }
                    } else {
                        log.info("----------所有家长都未入群----------familyListAll:{}", familyListAll.size());
                        List<Family> familyListByUserIds = getErrorFamilyList(familyListAll,null);
                        log.info("----------所有家长都未入群数量----------familyListByUserIds:{}", familyListByUserIds.size());
                        familyErrorList.addAll(familyListByUserIds);
                    }

                    if(CollectionUtils.isNotEmpty(familyErrorList)){
                        familyErrorList.forEach((e)->{
                            //删除家长对应删除IM账号缓存
                            ResultDTO<Object> imUserRedis = tcCloudFeignService.getImUserRedis(e.getUserId(), e.getOrgId(), (short) RoleTypeEnum.FAMILY.getValue(), UserTypeEnum.FAMILY.getValue().shortValue());
                            if (ResultDTO.checkSuccess(imUserRedis) && null != imUserRedis.getData()) {
                                log.info("----------清除该用户IM缓存----------userId:{}", e.getUserId());
                                redisTemplateUtil.delete(imUserRedis.getData().toString());
                            }
                            ThreadPoolUtil.addTask(new ImRepairImClassGroupInfoTask(e.getUserId(),e.getOrgId(), userOpenService));
                        });
                    }
                }
            }*/
        } catch (Exception e) {
            log.error("----------查询当前学校需要修复的IM家长用户异常----------{}", e.getMessage());
        }
        log.info("----------处理IM家长数据结束----------");
    }

}
